package com.tinelion.flyer.dao;

import com.tinelion.flyer.entity.RoleEntity;
import com.tinelion.flyer.entity.UserEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

@Repository
@Mapper
public interface UserDao {

    @Select("SELECT * FROM user WHERE user_name=#{userName}")
    UserEntity getUser(@Param("userName") String userName);

    @Select("SELECT a.is_access  FROM role a inner jone user b on a.user_id=b.id WHERE b.id=#{id}")
    int getpower(@Param("id")int id);

    @Insert("INSERT INTO user (email,user_name,password,salt,created_time) VALUES (#{email},#{userName},#{password},#{salt},#{time})")
    int add(@Param("email") String email,
            @Param("userName") String userName,
            @Param("password") String password,
            @Param("salt")String salt,
            @Param("time")String time);

    @Insert("INSERT INTO role (user_id,role,is_access) VALUES (#{userId},#{role},#{isAccess})")
    int addrole(@Param("userId")int userId,
                @Param("role")String role,
                @Param("isAccess")int isAccess);


    @Select("SELECT * FROM role where user_id=#{id}")
    RoleEntity getRole(@Param("id")int id);

}
